//Tue Jul 26 18:17:31 IST 2011

#include <stdio.h>
#include <string.h>


int N, counter = 0;

void permute (char *str, int d)
{
	if (d == N) {
		printf("%d: %s\n", ++counter, str);
		return;
	} else {
		int i;
		for (i=d; i < N; i++) {
			char t;

			//swap
			t = str[d];
			str[d] = str[i];
			str[i] = t;

			permute(str, d+1);

			//swap
			t = str[d];
			str[d] = str[i];
			str[i] = t;
		}
	}
}


int main()
{
	char string[]= "Sankar";

	N = strlen(string);
	permute (string, 0);

	printf("counter : %d", counter);

	return 0;
}
//Tue Jul 26 19:04:53 IST 2011 - Unfair. As I was out most of the time. It took around 15 mins, still bad though.
